package cn.xuchunh.campusbbs.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.ViewGroup;

import cn.xuchunh.campusbbs.R;
import cn.xuchunh.campusbbs.base.BaseRecyclerViewAdapter;
import cn.xuchunh.campusbbs.bean.Forum;
import cn.xuchunh.campusbbs.utils.DateUtil;
import cn.xuchunh.campusbbs.viewholder.ForumViewHolder;

/**
 *
 * Created by XuChunH on 2015/9/12.
 */
public class CommunityAdapter extends BaseRecyclerViewAdapter<ForumViewHolder, Forum> {

    public CommunityAdapter(Context context) {
        super(context);
    }

    @Override
    public ForumViewHolder onCreateContentViewHolder(ViewGroup parent, int viewType) {
        return new ForumViewHolder(inflater.inflate(R.layout.item_forum2, parent, false));
    }

    @Override
    protected void onBindContentViewHolder(ForumViewHolder holder, int position) {
        Forum forum = dataList.get(position);
        holder.name.setText(forum.getName());
        holder.lastPostTime.setText(DateUtil.formatDate(forum.getLastPostsDate()));
        int count = forum.getTodayPostsNum();
        if(count < 1){
            holder.todayPostNum.setBackGroundColor(getContext().getResources().getColor(R.color.grey_500));
        }else {
            holder.todayPostNum.setBackGroundColor(getContext().getResources().getColor(R.color.red_500));
        }
        holder.todayPostNum.setNum(count + "");
        holder.icon.setImageURI(Uri.parse(forum.getIcon()));
    }

}
